package com.inspur.zhangpeixia.goods.service.impl;

import com.inspur.zhangpeixia.goods.dao.LoginDao;
import com.inspur.zhangpeixia.goods.entity.User;
import com.inspur.zhangpeixia.goods.service.LoginService;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class LoginServiceImpl implements LoginService {
    private LoginDao loginDao=new LoginDao();
    @Override
    public User login(String userAaccount, String userPassword) {
        String md5Password=getMD5(userPassword);
        System.out.println(md5Password);
        return loginDao.login(userAaccount,md5Password);
    }
    public static String getMD5(String password) {
        try {
            // 获取 MD5 算法的 MessageDigest 对象
            MessageDigest md = MessageDigest.getInstance("MD5");
            // 将输入字符串转换为字节数组并进行哈希计算
            byte[] messageDigest = md.digest(password.getBytes());
            // 将字节数组转换为十六进制字符串
            StringBuilder hexString = new StringBuilder();
            for (byte b : messageDigest) {
                String hex = Integer.toHexString(0xff & b);
                if (hex.length() == 1) {
                    hexString.append('0');
                }
                hexString.append(hex);
            }
            return hexString.toString();
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }




}
